/*
 * @Author: hucc
 * @Date: 2021-09-26 11:23:59
 * @LastEditors: hucc
 * @LastEditTime: 2021-09-26 16:50:15
 * @Description: 
 */
//Array.from() 构造函数方法 其他数据类型转成数组类型  只可转码可迭代的对象
//可迭代的：字符串 类数组对象 数组

//类数组对象  Array.prototype.slice.call("类数组对象",0)
// let arrobj = {
//     0: "zs",
//     1: "lisi",
//     2: "ww",
//     length: 3
// }
let obj = "hello"
    //用数组原型方法进行切割
let a = Array.prototype.slice.call(obj, 0)
console.log(a); //[ 'h', 'e', 'l', 'l', 'o' ]
// let arr1 = Array.from(obj)
// console.log(arr1); //[ 'h', 'e', 'l', 'l', 'o' ]
// console.log(Array.from(arrobj)); //[ 'zs', 'lisi', 'ww' ]
// let obj1 = {
//     name: "zs",
//     age: 12
// }
// console.log(Array.from(obj1)); //[]


//Array.of() 创建数组实例 实参就是数组的元素 
//解决es5中 var arr=new Array(5) 输出的是长度为5 [5empties]
let arr2 = Array.of(1, 2, 3, 4, 5, 6)
    //let arr2=Array.of(3);
    // console.log(arr2);//[3]

//Array.prototype.find() 满足返回条件的第一个参数 没有满足条件的返回undefined 
let result = arr2.find((item, index) => {
    return item > 2
})
console.log(result); //3

//Array.prototype.findIndex() 满足返回条件的第一个索引下标 不满足返回-1
let result1 = arr2.findIndex((item, index) => {
    return item > 2
})
console.log(result1); //2

//Array.prototype.include() 是否包含某个指定的元素
console.log(arr2.includes(7)); //false

//Array.prototype.fill() 填充数组 修改原数组
// let result2 = arr2.fill(7)
// console.log(result2, arr2, result2 === arr2); //[ 7, 7, 7, 7, 7, 7 ] [ 7, 7, 7, 7, 7, 7 ] true

//Array.prototype.keys()
//Array.prototype.values()
//Array.prototype.entries()
let keys = arr2.keys();
let values = arr2.values();
let entries = arr2.entries();
console.log(keys, values, entries); //Object [Array Iterator] {} Object [Array Iterator] {} Object [Array Iterator] {}
console.log(Array.from(keys)); //[ 0, 1, 2, 3, 4, 5 ]
console.log(Array.from(values)); //[ 1, 2, 3, 4, 5, 6 ]
console.log(Array.from(entries)); //[ [ 0, 1 ], [ 1, 2 ], [ 2, 3 ], [ 3, 4 ], [ 4, 5 ], [ 5, 6 ] ]